<?php /* <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> */?>
<?php 
	$keyword = urldecode($_POST['keyword']);
	$save = strip_tags($_POST['save']);
	$orderBy= strip_tags($_POST['orderBy']);
	
	include("class/class.data.php");
	$db = new data_class;
	if($keyword != "" && ($save == '0' || $save == '1')) {
		$sql = "UPDATE keyword SET save = '" . $save ."' WHERE word = '".addslashes($keyword)."'";
		$db->execute($sql);
	}
	if($save == '8') {
		$sql = "SELECT * FROM keyword WHERE word = '" . addslashes($keyword) ."'";
	}
	else {
		if($orderBy == 'asc') {
			$sql = "SELECT * FROM keyword WHERE save = '9' AND `count` > '9' ORDER BY count ASC LIMIT 0,1;";
		} else {
			$sql = "SELECT * FROM keyword WHERE save = '9' ORDER BY count DESC LIMIT 0,1;";
		}
	}
	$res = $db->query($sql);
	$keywordNext = $res[0]->word;
	$countNext = $res[0]->count;
	$classNext = $res[0]->class;
//	$left = $db->result_query("SELECT save FROM keyword WHERE save = '9';");
?>
<table border="1" width="100%">
  <tr>
    <td width="86">Keyword</td>
    <td ><div id="keyword"><?php echo $keywordNext; ?></div></td>
  </tr>
  <tr>
    <td>Count </td>
    <td><div id="count"><?php echo $countNext; ?></div></td>
  </tr>
  <tr>
    <td>Class</td>
    <td><div id="class"><?php echo $classNext ?></div></td>
  </tr>
  <tr>
    <td>Save it?</td>
    <td><div id="saveBox">
    	<input type="button" id="saveYes" value="Yes" onclick="fun_saveYes();" class="button"/>
        &nbsp;&nbsp;
        <input type="button" id="saveNo" value="No" onclick="fun_saveNo();"/>
        </div></td>
  </tr>
  <tr>
  <td>Last Word</td>
  <td><div id="lastword" onclick="fun_lastWord();"><?php echo ($keyword == "" ? "&nbsp;" : $keyword); ?></div></td>
  </tr>
</table>